package com.smart.controller;

import com.smart.common.WebResponse;
import com.smart.common.annotation.WebAccess;
import com.smart.common.PageInfo;
import com.smart.model.request.OperateProjectRequest;
import com.smart.model.request.ProjectUseControlRequest;
import com.smart.service.ProjectUseControlService;
import com.smart.model.vo.ProjectUseControlVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/control")
@Api(value = "运营平台#项目使用模块", tags = {"运营平台#项目使用模块"})
public class ProjectUseControlController {

    @Autowired
    private ProjectUseControlService projectUseControlService;

    @WebAccess(login = true)
    @ApiOperation("项目使用控制分页查询")
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<ProjectUseControlVO>> pageQuery(@RequestBody OperateProjectRequest request) {
        return WebResponse.build(projectUseControlService.pageQuery(request));
    }

    @WebAccess(login = true)
    @ApiOperation(value = "根据项目id查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{projectId}")
    public WebResponse<ProjectUseControlVO> getByKey(@PathVariable("projectId") long projectId) {
        return WebResponse.build(projectUseControlService.getByProjectId(projectId));
    }

    @WebAccess(login = true)
    @ApiOperation("编辑")
    @PostMapping("/update")
    public WebResponse<Boolean> updateByKey(@Valid @RequestBody ProjectUseControlRequest request) {
        return WebResponse.build(projectUseControlService.updateByKey(request));
    }

    @WebAccess(login = true)
    @ApiOperation("人员管理开通校验")
    @PostMapping("/manageOpenValid/{projectId}")
    public WebResponse<Boolean> manageOpenValid(@PathVariable("projectId") long projectId) {
        return WebResponse.build(projectUseControlService.manageOpen(projectId));
    }

    @WebAccess(login = true)
    @ApiOperation("数据提报开通校验")
    @PostMapping("/reportOpenValid/{projectId}")
    public WebResponse<Boolean> reportOpenValid(@PathVariable("projectId") long projectId) {
        return WebResponse.build(projectUseControlService.reportOpenValid(projectId));
    }

    @WebAccess(login = true)
    @ApiOperation("动火作业开通校验")
    @PostMapping("/hotWorkOpenValid/{projectId}")
    public WebResponse<Boolean> hotWorkOpenValid(@PathVariable("projectId") long projectId) {
        return WebResponse.build(projectUseControlService.hotWorkOpenValid(projectId));
    }

    @WebAccess(login = true)
    @ApiOperation("动火作业开通校验")
    @PostMapping("/hotWorkOpenStatus/{projectId}")
    public WebResponse<Boolean> hotWorkOpenStatus(@PathVariable("projectId") long projectId) {
        return WebResponse.build(projectUseControlService.hotWorkOpenStatus(projectId));
    }

    @WebAccess(login = true)
    @ApiOperation("卡点提示")
    @PostMapping("/tip/{projectId}")
    public WebResponse<Boolean> tip(@PathVariable("projectId") long projectId) {
        return WebResponse.build(projectUseControlService.tip(projectId));
    }

    @WebAccess(login = true)
    @ApiOperation("当前无动火作业")
    @PostMapping("/noHotWork/{projectId}")
    public WebResponse<Boolean> noHotWork(@PathVariable("projectId") long projectId) {
        return WebResponse.build(projectUseControlService.noHotWork(projectId));
    }
}
